package com.system.orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.bean.Orders;
import com.system.common.service.IOrdersService;
import com.system.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @DubboReference
    IOrdersService ordersService;

    @PostMapping("/add")
    public Result add(Orders orders){
        ordersService.addOrders(orders);
        return Result.ok("添加成功");
    }

    @PutMapping("/update")
    public Result update(Orders orders){
        ordersService.updateOrders(orders);
        return Result.ok("修改成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(Integer id){
        ordersService.deleteOrders(id);
        return Result.ok("删除成功");
    }

    @GetMapping("/getOrdersById/{id}")
    public Result getOrdersById(Integer id){
        Orders orders = ordersService.getOrdersById(id);
        return Result.ok("查找成功",orders);
    }

    @GetMapping("/getOrdersByOrderNo/{orderno}")
    public Result getOrdersByOrderNo(String orderNo){
        Orders orders = ordersService.getOrdersByOrderNo(orderNo);
        return Result.ok("查找成功",orders);
    }

    @GetMapping("/list")
    public Result getOrdersList(){
        return Result.ok("查找成功",ordersService.getOrdersList());
    }

    @GetMapping("/page")
    public Result getPage(Orders orders, Integer pageNum, Integer pageSize){
        return Result.ok("查找成功",ordersService.getPage(orders,new Page<Orders>(pageNum,pageSize)));
    }
}
